const jokeEl = document.getElementById('joke');
const jokeBtn = document.getElementById('joke-btn');

const generateJoke = () => {
  const xhr = new XMLHttpRequest();
  xhr.open('GET', 'https://api.chucknorris.io/jokes/random', true)
  xhr.onreadystatechange = function () {
    if (this.readyState === 4 && this.status === 200) {
      const jokeData = JSON.parse(this.responseText);
      jokeEl.innerHTML = jokeData.value
    } else {
      jokeEl.innerHTML = 'Error 不好笑'
    }
  }
  xhr.send()
}
jokeBtn.addEventListener('click', generateJoke);

